package com.snowcattle.game.service.dict;

import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * map形数据字典，每个对应一个数组
 */
public class DictArrayMaps implements IDictCollections {

    private Map<Integer, IDict[]> dictMap;

    public DictArrayMaps() {
        this.dictMap = new ConcurrentHashMap<>();
    }

    public void put(int id, IDict[] dicts) {
        this.dictMap.put(id, dicts);
    }

    public IDict[] getDictArary(int id) {
        return dictMap.get(id);
    }

    @Override
    public Collection<IDict> getAllDicts() {
        List<IDict> list = dictMap.values().stream().flatMap(arr -> Stream.of(arr)).collect(Collectors.toList());
        return list;
    }

}
